package com.ruoyi.blindBoxManage.controller;

import com.ruoyi.blindBoxManage.domain.ProductType;
import com.ruoyi.blindBoxManage.service.IProductTypeService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品等级配置Controller
 *
 * @author ruoyi
 * @date 2025-08-12
 */
@RestController
@RequestMapping("/productType/productType")
public class ProductTypeController extends BaseController {
    @Autowired
    private IProductTypeService productTypeService;

    /**
     * 查询商品等级配置列表
     */
    @PreAuthorize("@ss.hasPermi('productType:productType:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductType productType) {
        startPage();
        List<ProductType> list = productTypeService.selectProductTypeList(productType);
        return getDataTable(list);
    }

    /**
     * 导出商品等级配置列表
     */
    @PreAuthorize("@ss.hasPermi('productType:productType:export')")
    @Log(title = "商品等级配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductType productType) {
        List<ProductType> list = productTypeService.selectProductTypeList(productType);
        ExcelUtil<ProductType> util = new ExcelUtil<ProductType>(ProductType.class);
        util.exportExcel(response, list, "商品等级配置数据");
    }

    /**
     * 获取商品等级配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('productType:productType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(productTypeService.selectProductTypeById(id));
    }

    /**
     * 新增商品等级配置
     */
    @PreAuthorize("@ss.hasPermi('productType:productType:add')")
    @Log(title = "商品等级配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductType productType) {
        return toAjax(productTypeService.insertProductType(productType));
    }

    /**
     * 修改商品等级配置
     */
    @PreAuthorize("@ss.hasPermi('productType:productType:edit')")
    @Log(title = "商品等级配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductType productType) {
        return toAjax(productTypeService.updateProductType(productType));
    }

    /**
     * 删除商品等级配置
     */
    @PreAuthorize("@ss.hasPermi('productType:productType:remove')")
    @Log(title = "商品等级配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(productTypeService.deleteProductTypeByIds(ids));
    }
}
